package com.hy.common.pool;

import com.alibaba.excel.exception.ExcelAnalysisException;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class ThreadPool {




    public static ThreadPoolExecutor poolExecutor=new ThreadPoolExecutor(
            2  , //核心线程数
            Runtime.getRuntime().availableProcessors(),//当前主机够分配的最大线程数
            30,//线程存活时间
            TimeUnit.SECONDS,
            new LinkedBlockingDeque<Runnable>(10000),// 一个无界队列
            Executors.defaultThreadFactory(),//默认的线程工厂
            new ThreadPoolExecutor.AbortPolicy()
    );

//    public static ThreadPoolExecutor poolExecutor=new ThreadPoolExecutor(
//            6  , //核心线程数
//            Runtime.getRuntime().availableProcessors(),//当前主机够分配的最大线程数
//            30,//线程存活时间
//            TimeUnit.SECONDS,
//            new LinkedBlockingDeque<Runnable>(10000),// 一个无界队列
//            new ThreadFactoryBuilder().setNameFormat("customThread %d")
//                    .setUncaughtExceptionHandler((t, e) -> {
//
//                                System.err.println(t.getName() + "发生异常" + e.getCause());
//                                throw  new ExcelAnalysisException(e.getMessage());
//                            }
//
//                    )
//                    .build()
//    );
}
